package cn.hutool.core.io.file;

import java.util.HashMap;
import java.util.Map;


/**
 * 基于内存管理文件的导入导出
 * @author 蓝大叔
 */
public class InMemoryFile {
    private String name;
    private boolean isDirectory;
    private byte[] content;
    private Map<String, InMemoryFile> children;
    private InMemoryFile parent;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public boolean isDirectory() {
        return isDirectory;
    }

    public void setDirectory(boolean directory) {
        isDirectory = directory;
    }

    public byte[] getContent() {
        return content;
    }

    public void setContent(byte[] content) {
        this.content = content;
    }

    public Map<String, InMemoryFile> getChildren() {
        return children;
    }

    public void setChildren(Map<String, InMemoryFile> children) {
        this.children = children;
    }

    public InMemoryFile getParent() {
        return parent;
    }

    public void setParent(InMemoryFile parent) {
        this.parent = parent;
    }

    public InMemoryFile(String name, boolean isDirectory) {
        this.name = name;
        this.isDirectory = isDirectory;
        if (isDirectory) {
            this.children = new HashMap<>();
        }
    }

    public void addChild(InMemoryFile child) {
        if (!isDirectory) {
            throw new IllegalStateException("Cannot add child to a file");
        }
        children.put(child.getName(), child);
        child.setParent(this);
    }

}
